home *** CD-ROM | disk | FTP | other *** search
- Path: news.nic.surfnet.nl!sun4nl!ittpub!ittpub!nntp
- Newsgroups: comp.lang.c++
- Subject: Re: Question about destructor...
- Message-ID: <1996Jan4.134423.1728@ittpub>
- From: wil@ittpub.nl (Wil Evers)
- Date: 4 Jan 96 13:44:22 WET
- References: <4ces35$3iq$1@mhafn.production.compuserve.com>
- Distribution: world
- Nntp-Posting-Host: lintilla
-
- In article <4ces35$3iq$1@mhafn.production.compuserve.com> Nil Bannerjee
- <100704.1417@CompuServe.COM> writes:
-
- [previous discussion: what should derived class CB's destructor do to make
- sure base class CA's destructor is called?]
-
- > If you call the destructor of A from B's destructor then this
- > will take care of the inherited attributes.
- >
- > CB::~CB()
- > {
- > //your stuff..
- > ..
- > ..
- > ~CA();
- > }
-
- Sorry, but this is wrong! If you manage to explicitly call the base class
- destructor from the derived class destructor, the base class destructor
- will be called twice, because the base class destructor is called
- automatically after running the derived class destructor code. So in all
- but the most akward cases, a derived class destructor should not try to
- call the base class destructor.
-
- Apart from that, the code above should not compile. If you ever need to
- explicitly call a destructor, you must explicitly specify the object on
- which it is to be called:
-
- class SomeClass {
- public :
- virtual ~SomeClass();
- void destruct()
- { this->~SomeClass(); }
- // may call derived destructor first
- void destroy()
- { this->SomeClass::~SomeClass(); }
- // always calls SomeClass::~SomeClass() directly
- };
-
- - Wil
-
-
-